package main.Q1401_1500;

import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;

public class Q1421_1430 {
    public static void main(String[] args) {
        System.out.println("Question1421：");
        System.out.println("Question1422：");
        System.out.println("Question1423：可获得的最大点数");
        System.out.println("Question1424：对角线遍历 II");
        System.out.println("Question1425：");
        System.out.println("Question1426：");
        System.out.println("Question1427：");
        System.out.println("Question1428：");
        System.out.println("Question1429：");
        System.out.println("Question1430：");
    }
}

class Question1423 {
    public int maxScore(int[] cardPoints, int k) {
        int minLength = cardPoints.length - k;
        int left = 0, right = cardPoints.length - k - 1, total = 0, minTotal = 0, min = 0;
        for (int i = 0; i < cardPoints.length - k; i++) {
            total += cardPoints[i];
            minTotal += cardPoints[i];
        }
        min = minTotal;
        right++;
        left++;
        while (right < cardPoints.length) {
            total += cardPoints[right];
            minTotal -= cardPoints[left - 1];
            minTotal += cardPoints[right];
            min = Math.min(min, minTotal);
            left++;
            right++;
        }
        return total - min;
    }
}

class Question1424 {
    public int[] findDiagonalOrder(List<List<Integer>> nums) {
        int size = 0;
        for (int i = 0; i < nums.size(); i++) {
            size += nums.get(i).size();
        }
        int[] result = new int[size];
        PriorityQueue<int[]> queue = new PriorityQueue<>((a, b) -> a[0] - b[0]);
        int index = 0;
        queue.add(new int[]{index++, 0, 0});
        while (!queue.isEmpty()) {
            int[] cur = queue.poll();
            result[cur[0]] = nums.get(cur[1]).get(cur[2]);
            if (cur[2] == 0 && cur[1] + 1 < nums.size()) {
                queue.add(new int[]{index++, cur[1] + 1, 0});
            }
            if (nums.get(cur[1]).size() > cur[2] + 1) {
                queue.add(new int[]{index++, cur[1], cur[2] + 1});
            }
        }
        return result;
    }
}